import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class test2 {
    public static void main(String[] args) throws IOException {
        // 创建字符输入流和输出流
        FileReader reader = null;
        FileWriter writer = null;

        try {
            // 创建输入流和输出流对象
            reader = new FileReader("D:\\1.txt");
            writer = new FileWriter("D:\\2.txt");
            // 读取输入流中的字符，并写入输出流中
            int c;
            while ((c = reader.read()) != -1) {
                writer.write(c);
            }
            System.out.println("文件内容复制完成。");
        } finally {
            // 关闭输入流和输出流
            if (reader != null) {
                reader.close();
            }
            if (writer != null) {
                writer.close();
            }
        }
    }
}
